import fn from './knuthMorrisPratt'

let text = 'jojjjbjlljjbjj'


// 用一个数组记录 记录 如果这个不匹配 那么回到那个 节点重新比较

// [0, 1, 0, 1, ]

// 相当于就是对称
function buildPatternTable(word) {
  const patternTable = [0]

  let prefixIndex = 0;
  let suffixIndex = 1;

  while(suffixIndex<word.length) {
    if(word[prefixIndex] === word[suffixIndex]) {
      patternTable[suffixIndex] = prefixIndex+1
      suffixIndex += 1
      prefixIndex += 1
    }else if(prefixIndex==0) {
      patternTable[suffixIndex] = 0
      suffixIndex += 1
    }else{
      prefixIndex = patternTable[prefixIndex - 1];
    }
  }
  return patternTable;
}



let word = 'jjkbjjkb'
// 朝招
console.log(fn(text, word))